package com.ruleengine.worker.model;

import java.util.List;

import com.google.common.graph.Network;
import com.ruleengine.util.model.Metadata;

import lombok.Builder;
import lombok.Getter;

/**
 * @author lianghanwei on 2024/3/3
 */
@Builder(toBuilder = true)
@Getter
public class Chain {

    @Builder.Default
    private String apiVersion = "v1";

    @Builder.Default
    private ResourceKind kind = ResourceKind.CHAIN;

    private Metadata metadata;

    private Spec spec;

    private Status status;

    @Builder(toBuilder = true)
    @Getter
    public static class Spec {

        private State state;

        private List<Rule> rules;

        private List<Relation> relations;

        private Network<Rule, Relation> topology;

//        private BufferType bufferType;

//        @Builder.Default
//        private RunnerType runnerType = RunnerType.DISRUPTOR;

    }

    public enum State {
        DISABLED,
        ENABLED,
        BANNED,
        DELETED
    }

    public enum BufferType {
        MEMORY
    }

    public enum RunnerType {
        DISRUPTOR
    }

    public String getUniqueName() {
        return new StringBuilder()
            .append("/").append(apiVersion)
            .append("/").append(kind.name())
            .append("/").append(metadata.getUid())
            .append("/").append(metadata.getResourceVersion())
            .toString();
    }

}
